package com.demo.example;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.demo.service.ProviderClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.cloud.context.named.NamedContextFactory;
import org.springframework.cloud.loadbalancer.config.BlockingLoadBalancerClientAutoConfiguration;
import org.springframework.cloud.loadbalancer.config.LoadBalancerAutoConfiguration;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RefreshScope
public class ClientControl {


    @Value("${database.pwd}")
    private String test;
    @Autowired
    private ProviderClient client;
    @SentinelResource(value = "sayhello")
    @GetMapping(value = "/main1/tet")
    public  String test() throws InterruptedException {
        ///Thread.sleep(101);
        // if(true)
        //    throw   new RuntimeException("发生错误·");
        BlockingLoadBalancerClientAutoConfiguration  dd = null;
        NamedContextFactory ff = null;
        LoadBalancerAutoConfiguration fff = null;
//        return restTemplate.getForObject("http://testService/main/tet/lll123",String.class);
    return client.test("777777");
    }
    @SentinelResource(value = "relation")
    @GetMapping(value="/main/error",produces="application/json;charset=UTF-8")
    public String throwException()
    {
        return "ddd="+test;
       // throw new ResponseStatusException(HttpStatus.NOT_ACCEPTABLE,"没有炒找到",new RuntimeException("dd"));
    }
}
